package com.bilin.coin.network.callback;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


/**
 *
 */

public abstract class CommonCallBack2 implements Observer<String> {


    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(String s) {
        try {
            if (!s.equals("") && s != null) {
                onSuccess(s);
            } else {
                onCallBackError(new Throwable("-400", new Throwable("返回数据为空")));
            }
        } catch (Exception e) {
            onCallBackError(new Throwable("-500", new Throwable("网络开小差了")));
            e.printStackTrace();
        }
    }

    protected abstract void onError(String errorMsg);

    protected abstract void onSuccess(String dataJson);

    protected abstract void onCallBackError(Throwable e);

    @Override
    public void onError(Throwable e) {
        onCallBackError(e);
    }

    @Override
    public void onComplete() {

    }
}
